package num1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Scanner;

public class delete {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (Exception e) {
			// TODO: handle exception
		}
		Connection con = null;
		Statement st = null;
		String url = "jdbc:mysql://localhost:3306/作业";
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入要删除的编号");
		int id = sc.nextInt();
		try {
			con = DriverManager.getConnection(url, "zhwz", "zwz1234");
			st = con.createStatement();
			String sql = "delete from `subject` where id=" + id + "  ";
			System.out.println(sql);
			int i = st.executeUpdate(sql);
			System.out.println("删除了" + i + "条数据");
		} catch (Exception e) {
			e.printStackTrace;
		}finally {
			try {
				st.close();
				con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
